package com.wn.service.impl;

import com.wn.mapper.AccountMapper;
import com.wn.service.ITransferService;
import com.wn.service.LogService;
import org.slf4j.ILoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;


/**
 * @author yellow Docter
 * @date 2024-07-05
 * @desc 蜗牛创想：www.woniuxy.com
 */
@Service

public class TransferServiceImpl implements ITransferService {

    @Autowired
    private AccountMapper accountMapper;

    @Autowired
    private LogService logService;

    //业务层代码
    @Transactional
    @Override
    public void transfer(String inName, String outName, int money) throws IOException {

        try {
            //zs   转入
            accountMapper.inMoney(inName,money); //金额添加

            int a = 10 / 0;

            //lisi 转出   共同完成转账操作
            accountMapper.outMoney(outName,money);  //金额没有减少

        }finally {
            //记录日志
            logService.log(outName,inName,money);
        }

    }

//    @Transactional(
//            readOnly = true,
//            timeout = 5,
//            rollbackFor ={}  //spring默认的事 rollbackFor RuntimeException  运行异常
//            //自定义的异常  最后是 RuntimeException 的子类
//    )  //这是个只读事务
//
//    public void list(){
//
//        IOException exception;
//    }

}
